//
//  SISSRegistrationView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/3/15.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSRegistrationView.h"
#import "SISSRegistrationViewController.h"

@implementation SISSRegistrationView

- (void)initUI {
    
    [super initUI];
    
    
    UIView *view = [[UIView alloc] init];
    [self addSubview:view];
    CGSize size = CGSizeMake(SCREEN_WIDTH - 40, 80);
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(SCREEN_HEIGHT * 0.25);
        make.size.mas_equalTo(size);
    }];
    
//    SISSRegistrationViewController *vc = [[SISSRegistrationViewController alloc] init];
//    [view addSubview:vc.view];
//    vc.view.frame = view.bounds;

    
    
    NSArray *imageNames = @[@"1", @"2", @"3", @"4"];
    NSArray *titleNames = @[@"房源登录", @"客源登记", @"求购合作", @"出售合作"];
    
    // 循环创建四个按钮
    for (int i = 0; i < 4; i ++) {
        
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        // 创建属性文本对象
        NSAttributedString *attrStr = [NSAttributedString yyr_imageTextWithImage:[UIImage imageNamed:imageNames[i]] imageWH:60 title:titleNames[i] fontSize:11 titleColor:[UIColor yyr_colorWithHex:0x334A60] spacing:8];
        // 设置button的属性文本
        [button setAttributedTitle:attrStr forState:UIControlStateNormal];
        button.titleLabel.numberOfLines = 0;
        button.titleLabel.textAlignment = NSTextAlignmentCenter;
        [view addSubview:button];
        [button sizeToFit];
        button.tag = i;
        CGFloat margin = ((56 + 33) / 375.0) * SCREEN_WIDTH;
        button.frame = CGRectMake(i * margin, 10, 56, 56);
        
        [button addTarget:self action:@selector(buttonActoion:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    
    // 底部视图
    UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 47, SCREEN_WIDTH, 56)];
    bottomView.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.9];
    [self addSubview:bottomView];
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [bottomView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(bottomView);
        make.height.mas_equalTo(1);
    }];
    
    // 底部取消按钮
    UIButton *deleteButton = [[UIButton alloc] init];
    [deleteButton setImage:[UIImage imageNamed:@"guanbi"] forState:UIControlStateNormal];
    [deleteButton sizeToFit];
    [deleteButton addTarget:self action:@selector(cancellButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton setBackgroundColor:[UIColor clearColor]];
    [bottomView addSubview:deleteButton];
    [deleteButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(bottomView);
        
    }];
}

- (void)buttonActoion:(UIButton *)button {
    
    if (self.buttonClickBlock) {
        self.buttonClickBlock((int)button.tag);
    }
}

- (void)cancellButtonClick:(UIButton *)button {
    
    
    [self removeFromSuperview];
}

@end
